<?php
namespace common\component\tool;

use Yii;
use common\component\exception\ErrMap;
use common\models\OperationLog;
use common\models\Album;
use common\component\tool\Tool;


class ImageUpload
{
    
    /*图片上传*/
    public function upload($post, $uploadFileName, $com_id = 0, $app_id = 0)
    {
        // P($com_id);
        // P($_FILES);
        if(isset($post['catId'])){//有相册ID
            if($_FILES){//有图片上传
                $album = new Album();
                if($fileName = $album->upload($post, $uploadFileName, $com_id, $app_id)){
                    $backInfo = [0, $fileName['url']];//返回信息
                }else{
                    if($album->hasErrors()){
                        $backInfo = ErrMap::getError(10005);//返回信息
                        $exception = $album->getErrors();//异常信息
                    }
                }
            }
        }else{//没有相册ID  
            $backInfo = ErrMap::getError(10016);//返回信息
        }

        if(!isset($backInfo)){
            $backInfo = ErrMap::getError(10005);//返回信息
        }
        if(!isset($exception)){
            $exception = '';//异常信息
        }
        //操作日志
        if(gettype( $res = OperationLog::addLog(Tool::operationLogArgs($backInfo), $exception) ) != 'boolean'){
            return $res;
        };
    }

}
?>

